package com.longxi.tianjintianbao.ui.adapter.multitype;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.SelectQualityClassListListener;
import com.longxi.tianjintianbao.model.quality.QualityClass;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class QualityClassListViewBinder extends ItemViewBinder<QualityClass, QualityClassListViewBinder.ViewHolder> {

    SelectQualityClassListListener listener;

    public QualityClassListViewBinder(SelectQualityClassListListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_quality_class, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull QualityClass qualityClass) {
        holder.mTvClassname.setText(qualityClass.getClassname());
        holder.mTvItem.setText(qualityClass.getItem() + "项");
        holder.mTvScore.setText(qualityClass.getScore() + "分");

        holder.mLlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onSuccess(qualityClass.getClassid(), qualityClass.getClassname());
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mLlBtn;
        TextView mTvClassname;
        TextView mTvItem;
        TextView mTvScore;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvClassname = itemView.findViewById(R.id.tvClassname);
            mTvItem = itemView.findViewById(R.id.tvItem);
            mTvScore = itemView.findViewById(R.id.tvScore);
        }
    }
}
